package com.yq.spbYq.mapper;


import com.yq.spbYq.Points;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface PointsMapper {

    // 查询所有积分记录
    @Select("SELECT * FROM points")
    @Results({
            @Result(property = "pointsId", column = "points_id"),
            @Result(property = "residentId", column = "resident_id"),
            @Result(property = "points", column = "points"),
            @Result(property = "lastUpdated", column = "last_updated")
    })
    List<Points> selectAllPoints();

    // 根据居民ID查询积分记录
    @Select("SELECT * FROM points WHERE resident_id = #{residentId}")
    @Results({
            @Result(property = "pointsId", column = "points_id"),
            @Result(property = "residentId", column = "resident_id"),
            @Result(property = "points", column = "points"),
            @Result(property = "lastUpdated", column = "last_updated")
    })
    Points selectPointsByResidentId(Integer residentId);

    // 新增积分记录
    @Insert("INSERT INTO points(resident_id, points) VALUES(#{residentId}, #{points})")
    int insertPoints(Points points);

    // 更新积分记录
    @Update("UPDATE points SET points = #{points} WHERE resident_id = #{residentId}")
    int updatePointsByResidentId(Points points);

    // 根据居民ID删除积分记录
    @Delete("DELETE FROM points WHERE resident_id = #{residentId}")
    int deletePointsByResidentId(Integer residentId);
}